/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MessageBeans;

import beans.JmsActionFacadeLocal;
import entities.JmsAction;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
import javax.ejb.MessageDriven;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
import services.IConstants;

/**
 *
 * @author corneliugosa
 */
@MessageDriven(mappedName = "jms/ScheduleExam", activationConfig = {
    @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
    @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class ExamRequest implements MessageListener{
    @EJB
    private JmsActionFacadeLocal jmsActionFacade;
    
    public void onMessage(Message message) {
        ObjectMessage msg = null;
        if (message instanceof ObjectMessage) {
            try {
                msg = (ObjectMessage) message;

                int code = Integer.parseInt(msg.getStringProperty("code"));
                if (code==100){
                    System.out.println("Exam schedule request sent!");
                }

            } catch (JMSException ex) {
                Logger.getLogger(ExamRequest.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    public JmsActionFacadeLocal getJmsActionFacade() {
        return jmsActionFacade;
    }

    public void setJmsActionFacade(JmsActionFacadeLocal jmsActionFacade) {
        this.jmsActionFacade = jmsActionFacade;
    }
    
}
